<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/WEB-INF/webpage/common/taglibs.jspf"%>
<!DOCTYPE html>
<html>
<head>
    <title><spring:message code="sys.role.authMenu" /></title>
    <meta name="decorator" content="form"/> 
    <html:css name="jquery-ztree"/>
    <html:js  name="jquery-ztree"/>
    <style>
	    .ibox-content {
	   	  padding: 0px 0px 0px;
	   	}
	</style>
</head>

<body class="white-bg"  formid="modelMenuOrgForm">
    <form:form id="modelMenuOrgForm" modelAttribute="data" action="${adminPath}/sys/report/saveBindOrg" method="post" class="form-horizontal">
		<form:hidden nested="false" path="reportId" defaultValue="${param.reportId}"/>
		<form:hidden nested="false" path="orgIds"/>
		<div>
			<div style="width: 25%;float: left">
				<ul id="orgTree" class="ztree"></ul>
			</div>
		</div>
	</form:form>
<script type="text/javascript">
var treeObj;
var orgs = ${orgs};//加载组织
var selects = ${selects};//已勾选数据

/**
 * @description 组织树的ztree配置 .<br>
 * @date 2018/3/19 .<br>
 * @author zcg .<br>
 */
var orgTreeSetting = {
	check: {
		enable: true
	},
	data: {
		key: {
			url: "notarget",
			icon: "notarget"
		},
		simpleData: {
			enable: true,
			idKey: "id",
			pIdKey: "parentId",
			rootPId: 0
		}
	}	
}
 
/**
 * @description 初始化加载JS .<br>
 * @date 2018/3/19 .<br>
 * @author zcg .<br>
 */
$(function(){
	initOrgTree();
});
 
/**
 * @description 初始化组织树 .<br>
 * @date 2018/3/19 .<br>
 * @author zcg .<br>
 */ 
function initOrgTree(){
		//初始化组织树
		treeObj=$.fn.zTree.init($("#orgTree"), orgTreeSetting, orgs);
		// 不选择父节点
		treeObj.setting.check.chkboxType = { "N" : "ps", "N" : "ps" };	
		for(var i=0; i<selects.length; i++) {
			var nodeid=selects[i].orgId;
			var node = treeObj.getNodeByParam("id", nodeid);
			try{treeObj.checkNode(node, true, false);}catch(e){}
		}
		treeObj.expandAll(true);
 }

/**
 * @description 提交前事件,检测是否配置了节点和菜单 .<br>
 * @date 2018/3/19 .<br>
 * @author zcg .<br>
 */
function beforeSubmit(){
	//获取勾选的组织,得到所有的组织Id集合
	var nodes = treeObj.getCheckedNodes(true);
	var selectids=[];
	for(var i=0; i<nodes.length; i++) {
		selectids[i]=nodes[i].id;
	}
	$("#orgIds").val(selectids);
	return true;
}

</script>
</body>
</html>